"""
 encoding    : utf-8
 @File       : commonfunctions.py
 @Author     : qin
 @Version    :
 @Description:
 @Date       : 2024/06/19
"""
import xlrd
from selenium import webdriver
from common.getabspath import getAbsPath
class Common:
    '''所有页面基础操作类'''
    @staticmethod
    def getDataFromXlsx(file_path):
        '''获取登录页面测试数据方法'''
        dataAbsPath = getAbsPath(file_path)
        file = xlrd.open_workbook(dataAbsPath)
        lg_msg_sheet1 = file.sheet_by_index(0)
        lg_msg_sheet2 = file.sheet_by_name('Sheet2')
        col_num = lg_msg_sheet1.ncols
        row_num = lg_msg_sheet1.nrows
        data_list = []
        for i in range(row_num):
            data_list.append(lg_msg_sheet1.row_values(i, 0, col_num))
        try:
            url_list = lg_msg_sheet2.row_values(0)
            data_list.append(url_list)
            return data_list
        except:
            return data_list



    @staticmethod
    def getElement(driver, name,path):
        '''定位元素的方法返回一个元素'''
        return driver.find_element(name,path)

    @staticmethod
    def getElements(driver, *ele):
        '''定位元素的方法返回一个元素列表'''
        return driver.find_elements(*ele)

    @staticmethod
    def openWeb(driver,url):
        '''打开浏览器并进入登录的页面'''
        return driver.get(url)

    @staticmethod
    def quitWeb(driver):
        '''关闭浏览器'''
        driver.quit()

    @staticmethod
    def screenshot(driver,name):
        '''遇到测试用例失败时一个截屏的方法'''
        logAbsPath = getAbsPath('log')
        logAbsPath = logAbsPath + '\\' + name
        driver.get_screenshot_as_file(logAbsPath)

if __name__ == '__main__':
    print(Common.getDataFromXlsx(r'data\zonghechaxun_data.xlsx')[2][2])
    # Common.getLoginDataFromXlsx()